package data

import (
	"context"
	"github.com/go-kratos/kratos/v2/log"
	"time"

	"VideoMemberCard/app/payment/service/internal/biz"
)

var _ biz.PaymentRepo = (*paymentRepo)(nil)

type paymentRepo struct {
	data *Data
	log  *log.Helper
}

func NewPaymentRepo(data *Data, logger log.Logger) biz.PaymentRepo {
	return &paymentRepo{
		data: data,
		log:  log.NewHelper(log.With(logger, "module", "repo/payment")),
	}
}

func (r *paymentRepo) CreatePayment(ctx context.Context, uid string) (bool, error) {
	// 可重复购买，但要防止不想购买而手贱点太快支付了最后要求退款的
	redisCmd := r.data.db.SetXX("paymentSet/service/"+uid, "1", 10*time.Second)
	return redisCmd.Result()
}
